#include "Semaphore.h"

Semaphore::Semaphore(size_t limit)
:count_(limit)
{

}
void Semaphore::post(){
    std::unique_lock<std::recursive_mutex> lock(mutex_);
    ++count_;
    cond_.notify_all();
}

void Semaphore::wait(){
    std::unique_lock<std::recursive_mutex> lock(mutex_);
    cond_.wait(mutex_,[this](){
               return count_>0;
               });
    --count_;
}
